package com.zhou.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginHandlerInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println(request.getRequestURI());
        String context = request.getContextPath();
        Object loginUser = request.getSession().getAttribute("loginUser");
        if (loginUser!=null){
            /*if ("/".equals(request.getRequestURI())){
                response.sendRedirect(context+"/index");
            }*/
            return true;
        }
        response.sendRedirect(context+"/");
        return false;
    }
}
